package DB_Layer;

import java.sql.*;

/**
 * Checks a table for max value of primary key
 * @author Group 5
 *
 */
public class GetMaxID {
	
	public GetMaxID() {
		
	}
	
	public static int getMaxID(String query) {
		ResultSet results;
		int id = -1;
		
		try {
			Statement statement = DbConnection.getInstance().getDBcon().createStatement();
			results = statement.executeQuery(query);
			
			if(results.next()) {
				id = results.getInt(1);
			}
		}
		catch(Exception e) {
			System.out.println("Query exception: Error in reading maxid" + e);
		}
		
		return id;
	}
}
